package service;

import Pojo.Applyout;
import Pojo.Checkout;
import Pojo.Zulist;
import dao.ApplyoutMapper;
import dao.CheckoutMapper;
import dao.HetongMapper;
import dao.HouselistMapper;
import dao.ZulistMapper;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class ApplyoutServiceImpl
  implements ApplyoutService
{

  @Autowired
  private ApplyoutMapper applyoutMapper;

  @Autowired
  private HouselistMapper houselistMapper;

  @Autowired
  private HetongMapper hetongMapper;

  @Autowired
  private CheckoutMapper checkoutMapper;

  @Autowired
  private ZulistMapper zulistMapper;

  public void insertapplyout(Zulist zulist)
  {
    Applyout applyout = new Applyout();
    applyout.setHouse_id(zulist.getHouse_id());
    applyout.setAddress(zulist.getAddress());
    applyout.setStatus("申请中");
    applyout.setUserlist_id(zulist.getUserlist_id());
    this.applyoutMapper.insertapplyout(applyout);
  }

  public List<Applyout> findallapplyout()
  {
    List list = this.applyoutMapper.findallapplyout();
    return list;
  }

  public void updateapplyout(Applyout applyout)
  {
    this.applyoutMapper.updateapplyout(applyout);
  }

  public void agreeapplyout(Integer id) {
    Applyout applyout = this.applyoutMapper.findbyid(id);
    this.houselistMapper.deletehousebyhouseid(applyout.getHouse_id());
    this.hetongMapper.deletehetong(applyout.getHouse_id());
    Checkout checkout = new Checkout();
    checkout.setHouse_id(applyout.getHouse_id());
    checkout.setAddress(applyout.getAddress());
    checkout.setStatus("已退租");
    checkout.setUserlist_id(applyout.getUserlist_id());
    this.checkoutMapper.insertcheckout(checkout);
    applyout.setStatus("已同意");
    this.applyoutMapper.updateapplyoutbyhouse(applyout);
    this.zulistMapper.deletezulist(applyout.getHouse_id());
  }

  public void deleteapplyout(Integer id)
  {
    this.applyoutMapper.deleteapplyout(id);
  }
}